<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="../vue.js"></script>

<body>
  <div id="app">
    <my-component> </my-component>
  </div>


  <script>
    // 注册组件
    Vue.component("my-component", {
      template: '<button @click="root">查看根实例</button>',
      methods: {
        root() {
          // 这里的this是指向vm的
          console.log(this.$root);

        }
      }
    })

    var vm = new Vue({
      el: "#app",
    })
  </script>

  <script>
    // 这里的this是指向window
    console.log(this);
  </script>
</body>

</html>